package com.cjzuji.rental;

import com.cjzuji.rental.util.Tool;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class test3 {
    public static void main(String[] args) {
        //String html = "<html>...</html>";
        // 这里应该是你的HTML数据，为了示例简洁，使用"..."代替
        // 实际上，你需要将html变量替换为从文件或网络读取的实际HTML内容
        // 例如：
        String cookie = "aliyungf_tc=fecde3fd631e4ae58fd7110ec40de3ac3cf8e643cad7f66978681c5f2fa8072e; canary-route=\"97cfbb012dcca95e\"; _csrf=febcc6a7008f5232fff1e1375ec781a8eea4b66805cec15cf775a507ca71e2dca%3A2%3A%7Bi%3A0%3Bs%3A5%3A%22_csrf%22%3Bi%3A1%3Bs%3A32%3A%22NezbZfDq00XtDkCBi7Ly8ob6v0COizcc%22%3B%7D; _c_WBKFRo=9iOHc0pHNMTLh2zfx54OuQeMGX7w4SqlHc9ebofW; _nb_ioWEgULi=; workOrderSixhour=1; workOrderDisposable=1; illegalWorkOrderSixhour=1; Go-Token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOjYxMjc3NjE2LCJleHAiOjE3NTQ3OTc0MzgsImlhdCI6MTc1NDUzODIzOCwic2NlbmUiOjUsInNlcnZlcl9pZCI6MjMxNzQsInVzZXJfaWQiOjYxMjc3NjE2fQ.WktjwADhf_5l2hRrc6G-rZioIo7w3FIfb6_dF4owb4E; Data-Token=6ff964b785cf4d14; Remember-Me=1; shuzhiSecret=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJwYy5tZXJjaGFudCIsInN1YiI6IjYxMjc3NjE2IiwiYXVkIjpbInBjLm1lcmNoYW50Il0sImV4cCI6MTc1NDc5NzQzOCwibmJmIjoxNzU0NTM4MjM4LCJpYXQiOjE3NTQ1MzgyMzgsImp0aSI6IjEzMzgxMTk0NDQ3Mzc2OTM5OTcxODYxMzIyOTg1NDM3IiwiSWQiOjYxMjc3NjE2LCJVc2VybmFtZSI6IuaftOaXpeaZtCIsIlBob25lIjoiMTQ3OTYzMjg5MzEiLCJJc0FkbWluIjpmYWxzZSwiUm9sZSI6InNlcnZlclN0YWZmIiwiU2VydmVySWQiOjIzMTc0LCJUZXJtaW5hbCI6IiJ9.OOonJoVzdjDcKCVgVeVc79-YXmiICNqfALr_9RRCZzE; _identity=aa09b520db0e710b91f0aacd04e8df4585f8d0f082c1fd2cf4ffcc6592197596a%3A2%3A%7Bi%3A0%3Bs%3A9%3A%22_identity%22%3Bi%3A1%3Bs%3A52%3A%22%5B61277616%2C%22tD9R3UHIrMrP3LEyHfZtulF6y-r3br76%22%2C259745%5D%22%3B%7D; RRZUJI_SE=rg16ir2eg4fhsuc4t8dhpspkou";
        String url = "https://admin.rrzu.com/v2-bill/index?order_id=2025062420113519";
        String html = Tool.getRequest(url,"","", "", cookie);
        try {
        // 解析HTML
             Document doc = Jsoup.parse(html);
        // 获取表格元素 Element
            Element table = doc.selectFirst("table.table.table-bordered");
        // 根据你的HTML调整选择器
             if (table != null) {
        // 获取表头（th）
                Elements headers = table.select("thead th");
                List<String> headerList = new ArrayList<>();
                for (Element header : headers)
                    {
                        headerList.add(header.text());
                    }
        // 获取表格内容（tbody中的tr和td）
                Elements rows = table.select("tbody tr");
                List<Map<String, String>> tableData = new ArrayList<>();
                for (Element row : rows) {
                    Elements cells = row.select("td");
                    Map<String, String> rowData = new HashMap<>();
                    for (int i = 0; i < cells.size() && i < headerList.size(); i++) {
        // 使用th的内容作为key，td的内容作为value
                        String headerText = headerList.get(i);
                        String cellText = cells.get(i).text();
                        rowData.put(headerText, cellText); }
                        tableData.add(rowData); }
        // 打印结果
                    for (Map<String, String> row : tableData) {
                        System.out.println(row);
                    }
             }
             else { System.out.println("未找到表格"); }
         }
         catch (Exception e) { e.printStackTrace(); }
    }
}